package com.apartment.service.house.impl;

import com.apartment.aop.MyLog;
import com.apartment.dao.HouseDao;
import com.apartment.entity.House;
import com.apartment.entity.SysLog;
import com.apartment.service.house.HouseService;
import com.apartment.util.PageVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HouseServiceImpl implements HouseService {
    @Autowired
    private HouseDao houseDao;

    @MyLog("2")
    @Override
    public List<House> findAll() {
        List<House> houseDaoAll = houseDao.findAll();
        return houseDaoAll;
    }

    @Override
    public void addLog(SysLog sysLog) {
        houseDao.addLog(sysLog);
    }

    @Override
    public PageVo<House> finAllPage(Integer limit, Integer page) {
        Page<House> page1 = new Page<>(page, limit);
        IPage<House> iPage = houseDao.selectPage(page1, null);
        List<House> list = iPage.getRecords();
        long count = iPage.getTotal();
        PageVo<House> pageVo = new PageVo<>();
        pageVo.setCode(0);
        pageVo.setMsg("");
        pageVo.setCount(count);
        pageVo.setData(list);

        return pageVo;
    }


}
